package com.bjsxt.common.util;

/**
 * 鍒嗛〉瀵硅薄
 * 
 * @author WangshSxt
 *
 */
public class PageInfoUtil
{
	private int totalRecord;

	private int pageSize = 10 ;

	private int currentPage;

	private int totalPage;

	private int prePage;

	private int nextPage;

	private int currentRecord;

	public int getTotalRecord()
	{
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord)
	{
		this.totalRecord = totalRecord;
	}

	public int getPageSize()
	{
		return pageSize;
	}

	public void setPageSize(int pageSize)
	{
		this.pageSize = pageSize;
	}

	public int getCurrentPage()
	{
		if(this.currentPage < 1)
		{
			this.currentPage = 1 ; 
		}

		if(this.getTotalRecord() > 0 && this.currentPage > this.getTotalPage())
		{
			this.currentPage = this.getTotalPage() ; 
		}
		return currentPage;
	}

	public void setCurrentPage(int currentPage)
	{
		this.currentPage = currentPage;
	}

	public int getTotalPage()
	{
		this.totalPage = (int) Math.ceil(1.0 * this.totalRecord / this.pageSize) ; 
		return totalPage;
	}

	public int getPrePage()
	{
		this.prePage = this.getCurrentPage() - 1 ; 
		if(this.prePage < 1)
		{
			this.prePage = 1 ; 
		}

		return prePage;
	}

	public int getNextPage()
	{
		this.nextPage = this.getCurrentPage() + 1 ; 

		if(this.getTotalRecord() > 0 && this.nextPage > this.getTotalPage())
		{
			this.nextPage = this.getTotalPage() ; 
		}
		return nextPage;
	}

	public int getCurrentRecord()
	{

		this.currentRecord = (this.getCurrentPage() - 1) * this.getPageSize() ;
		return currentRecord;
	}
	
	@Override
	public String toString()
	{
		return "PageInfoUtil [totalRecord=" + this.getTotalRecord() + ", pageSize=" + this.getPageSize() + ", currentPage=" + this.getCurrentPage()
				+ ", totalPage=" + this.getTotalPage() + ", prePage=" + this.getPrePage() + ", nextPage=" + this.getNextPage() + ", currentRecord="
				+ this.getCurrentRecord() + "]";
	}
	
	public static void main(String[] args)
	{
		PageInfoUtil pageInfoUtil = new PageInfoUtil() ; 
		pageInfoUtil.setTotalRecord(55);
		pageInfoUtil.setPageSize(10);
		pageInfoUtil.setCurrentPage(333);
		System.out.println(pageInfoUtil);
	}
}
